<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>GT pro钱包</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" href="css/card.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

		<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
		<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
		<style>
			.address {
				position: relative;
				/*display: inline-block;*/
				max-width: 300px;
				padding-right: 60px;
				line-height: 34px;
				overflow: hidden;
				/*内容超出后隐藏*/
				text-overflow: ellipsis;
				/* 超出内容显示为省略号*/
				white-space: nowrap;
				/*文本不进行换行*/
			}
			
			.address button {
				position: absolute;
				right: 0;
			}
		</style>
	</head>

	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">
			<div class="content-wrapper">
				<section class="content-header">
					<ol class="breadcrumb">
						<li>
							<a href="#"><i class="fa fa-dashboard"></i>项目方管理</a>
						</li>
						<li class="active">项目方列表</li>
					</ol>
				</section>
				<section class="content">
					<div class="box">
						<div class="box-header with-border">
							项目方列表
						</div>
						<div class="box-body">
							<div class="buyu_search_group">
								<div class="row" style="margin-bottom:10px;">
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">币种筛选</button>
											</div>
											<select type="text" class="form-control coin_id all" id="coin_id"></select>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">是否需要押金</button>
											</div>
											<!-- /btn-group -->
											<select type="text" class="form-control" id="need_pledge">
												<option value="">全部</option>
												<option value="1">需要</option>
												<option value="0">不需要</option>
											</select>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<button type="button" class="btn bg-primary margin" onclick="search()"><i class="fa fa-search" ></i>&nbsp;搜索</button>
										<button type="button" class="btn bg-primary margin" onclick="reset()"><i class="fa fa-trash" ></i>&nbsp;重置</button>
									</div>
									<div class="col-xs-12">
										<div class="fixed-table-toolbar margin">
											<div class="bs-bars pull-left">
												<div class="hidden-xs" id="managerTableToolbar" role="group">
													<button type="button" class="btn btn-primary " onclick="addproject()" id=""><i class="fa fa-plus"></i>&nbsp;新增</button>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- /.box-header -->
								<div class="box-body">
									<table id="example" class="display nowrap table table-bordered table-striped" style="width:100%;">
										<thead>
											<tr>
												<th>ID</th>
												<th>账号</th>
												<th>手机号码</th>
												<th>币数量</th>
												<th>地址</th>
												<th>是否需要押金</th>
												<th>备付金</th>
												<th>添加时间</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</section>
			</div>
		</div>
		<div class="modal fade parents in" id="addprojectModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	        
							<span aria-hidden="true">×</span>			
						</button>
						<h4 class="modal-title">添加项目方</h4>
					</div>
					<div class="modal-body">
						<div class="row">
							<label class="margin-bottom-none col-xs-12">账号
								<input type="text" class="form-control" name="account">
							</label>
							<label class="margin-bottom-none col-xs-12">密码
								<input type="text" class="form-control" name="password">
							</label>
							<label class="margin-bottom-none col-xs-12">手机号
								<input type="text" class="form-control" name="phone">
							</label>
							<label class="margin-bottom-none col-xs-12">币种
								<select type="text" class="form-control coin_id" name="coin_id"></select>
							</label>
							<label class="margin-bottom-none col-xs-12">项目方币地址
								<input type="text" class="form-control" name="address">
							</label>
							<label class="margin-bottom-none col-xs-12">usdt地址
								<input type="text" class="form-control" name="usd_address">
							</label>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="addSave()">确定</button>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade parents in" id="editprojectModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	        
							<span aria-hidden="true">×</span>			
						</button>
						<h4 class="modal-title">编辑项目方</h4>
					</div>
					<div class="modal-body">
						<div class="row">
							<input type="hidden" name="id" />
							<label class="margin-bottom-none col-xs-12">账号
								<input type="text" class="form-control" name="account">
							</label>
							<label class="margin-bottom-none col-xs-12">密码
								<input type="text" class="form-control" name="password">
							</label>
							<label class="margin-bottom-none col-xs-12">手机号
								<input type="text" class="form-control" name="phone">
							</label>
							<!--<label class="margin-bottom-none col-xs-12">押金充值
								<input type="text" class="form-control" name="pledge_num">
							</label>-->
							<label class="margin-bottom-none col-xs-12">地址
								<input type="text" class="form-control" name="address">
								<input type="hidden" name="orig_address"/>
							</label>
							<label class="margin-bottom-none col-xs-12">操作密码<span class="text-danger">(必填)</span>
								<input type="text" class="form-control" name="op_password">
							</label>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="editSave()">确定</button>
					</div>
				</div>
			</div>
		</div>

		<div class="modal fade parents in" id="passwordModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	        
							<span aria-hidden="true">×</span>			
						</button>
						<h4 class="modal-title">操作密码</h4>
					</div>
					<div class="modal-body">
						<div class="row">
							<input type="hidden" name="id" />
							<input type="hidden" name="status" />
							<label class="margin-bottom-none col-xs-12">操作密码<span class="text-danger">(必填)</span>
								<input type="password" class="form-control" name="op_password">
							</label>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="changeSave()">确定</button>
					</div>
				</div>
			</div>
		</div>

		<div class="modal fade parents in" id="transferModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	        
							<span aria-hidden="true">×</span>			
						</button>
						<h4 class="modal-title">分红</h4>
					</div>
					<div class="modal-body">
						<div class="row">
							<input type="hidden" name="id" />

							<label class="margin-bottom-none col-xs-12">币数量
								<div class="input-group">
									<input type="text" class="form-control" name="coin_num">
									<div class="input-group-btn">
										<!--<button type="button" " >-->
											<button name="coin_id" class="btn btn-default" aria-expanded="false">--</button>
										<!--</button>-->
									</div>
								</div>
							</label>
							<label class="margin-bottom-none col-xs-12">操作密码<span class="text-danger">(必填)</span>
								<input type="password" class="form-control" name="op_password">
							</label>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="transferSave()">确定</button>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade parents in" id="rechargeModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	        
							<span aria-hidden="true">×</span>			
						</button>
						<h4 class="modal-title">分红</h4>
					</div>
					<div class="modal-body">
						<div class="row">
							<input type="hidden" name="id" />
							<label class="margin-bottom-none col-xs-12">押金充值
									<input type="text" class="form-control" name="pledge_num">
							</label>
							<label class="margin-bottom-none col-xs-12">操作密码<span class="text-danger">(必填)</span>
								<input type="password" class="form-control" name="op_password">
							</label>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="rechargeSave()">确定</button>
					</div>
				</div>
			</div>
		</div>
		
		<div id='NewsToolBox'></div>
		<script src="bower_components/jquery/dist/jquery.min.js"></script>
		<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>

		<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
		<script src="bower_components/moment/min/moment.min.js"></script>
		<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
		<script src="dist/js/adminlte.min.js"></script>
		<script src="js/argument.js"></script>
		<script src="js/fun.js"></script>
		<script src="js/nav.js"></script>
		<script src="js/pop.js"></script>
		<script type="text/javascript">
			$.ajax({
				type: 'post',
				url: url + "Back_MainChainForCoin",
				contentType: "application/x-www-form-urlencoded",
				headers: {
					"auth-token": localStorage.getItem("wallet_token")
				},
				data: {
					data: JSON.stringify({
						page_num: 1
					})
				},
				dataType:'json',
				success: function(res) {
					console.log(res);
					if(res.status == 1000||res.status == 102) {
						ToLogin(res)
						return false;
					} else if(res.status != 1) {
						alert(res.error);
						return false;
					}
					$.each(res.data, function(index, item) {
						if(index == 0) {
							$(".coin_id.all").append("<option value=''>全部</option>")
						}
						$(".coin_id").append("<option value='" + item.id + "'>" + item.name + "</option>")
					})
				}
			})

			var table = $('#example').DataTable({
				'ordering': false,
				'lengthChange': false,
				'searching': false,
				'info': true,
				"processing": true,
				"serverSide": true,
				'scrollX':true,
				"ajax": {
					"type": 'post',
					"url": url + "Back_ProjectList",
					"contentType": "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"data": function(d) {
						var dataType = {
							need_pledge: {
								type: 'string',
								value: $("#need_pledge").val()
							},
							coin_id: {
								type: 'string',
								value: $("#coin_id").val()
							}
						}
						var Json = renderData(dataType);
						Json.page_num = d.start / 10 + 1;
						var data = {};
						data.data = JSON.stringify(Json);
						return data;
					},
					"dataFilter": function(data) {
						var datajson = eval('(' + data + ')');
						if(datajson.status == 1000||datajson.status == 102) {
							ToLogin(datajson)
							return false;
						} else if(datajson.status != 1) {
							alert(datajson.error);
							return false;
						}
						var json = {};
						if(datajson.data == null) {
							json.recordsTotal = 0;
							json.recordsFiltered = 0;
							json.data = [];
							return JSON.stringify(json);
						} else {
							json.recordsTotal = datajson.data.total;
							json.recordsFiltered = datajson.data.total;
							json.data = datajson.data.data_list;
							return JSON.stringify(json);
						}
					}
				},
				"columns": [{
						data: 'id'
					},
					{
						data: 'account'
					},
					{
						data: 'phone'
					},
					{
						data: null,
						render: function(data) {
							return data.pro_coin_num + "&nbsp;" + data.coin_name
						}
					},
					{
						data: null,
						render: function(data) {
							return '<div title="' + data.address + '" class="address" ><span class="address_content">' + data.address + '</span><button class="copy btn btn-primary button-margin">复制</button></div>'
						} //'address'
					},
					{

						data: null,
						render: function(data) {
							var text = "不需要",
								active = "";
							if(data.need_pledge == 1) {
								text = "需要";
								active = "active";
							}
							return '<div class="fr_swich Status ' + active + '" statusId="' + data.id + '"><div class="fr_swich_body"></div><span class="fr_swich_txt">' + text + ' </span></div></div>';
						}
					},
					{
						data: null,render:function(data){
							
							
							return data.pledge_num + "<input type='hidden' value='" + JSON.stringify(data) + "'>" + '<button type="button" class="btn btn-primary button-margin" onclick="recharge(this)" id=""><i class="fa fa-credit-card"></i>&nbsp;充值</button>'
						}
					},

					{
						data: 'add_time'
					},
					{
						data: null,
						render: function(data) {
							var str = "<input type='hidden' value='" + JSON.stringify(data) + "'>";
							check = '<button type="button" class="btn btn-primary button-margin" onclick="editProject(this)" id=""><i class="fa fa-edit"></i>&nbsp;修改</button><button type="button" class="btn btn-primary button-margin" onclick="Transfer(this)" id=""><i class="fa fa-search"></i>&nbsp;分红</button>';
							return str + check;
						}
					}
				]
			})
		</script>

		<script type="text/javascript">
			// 复制全文

			$("#example").on("click", ".copy", function() {

				var text = $(this).siblings(".address_content").text();
				console.log(text)
				var flag = copyText(text);
				move('success', '复制成功')
			})

			function copyText(text) {
				var textarea = document.createElement("textarea"); //创建input对象
				var currentFocus = document.activeElement; //当前获得焦点的元素
				var toolBoxwrap = document.getElementById('NewsToolBox'); //将文本框插入到NewsToolBox这个之后
				console.log(toolBoxwrap)
				toolBoxwrap.appendChild(textarea); //添加元素
				textarea.value = text;
				textarea.focus();
				if(textarea.setSelectionRange) {
					textarea.setSelectionRange(0, textarea.value.length); //获取光标起始位置到结束位置
				} else {
					textarea.select();
				}
				try {
					var flag = document.execCommand("copy"); //执行复制
				} catch(eo) {
					var flag = false;
				}
				toolBoxwrap.removeChild(textarea); //删除元素
				currentFocus.focus();
				return flag;
			}
		</script>

		<script type="text/javascript">
			function addproject() {
				$("#addprojectModal").modal('show');
				$("#addprojectModal input[type=text]").val("");
			}

			function addSave() {
				$.ajax({
					type: 'post',
					url: url + "Back_ProjectAdd",
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify({
							account: $("#addprojectModal [name=account]").val(),
							password: $("#addprojectModal [name=password]").val(),
							phone: $("#addprojectModal [name=phone]").val(),
							coin_id: $("#addprojectModal [name=coin_id]").val(),
							address: $("#addprojectModal [name=address]").val(),
							usd_address: $("#addprojectModal [name=usd_address]").val(),
						})
					},
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						move('success', res.error)
						$("#addprojectModal").modal("hide");
						table.draw(false);
					}
				})
			}
			//

			$("#example").on("click", ".Status", function() {
				var status = 1,
					_this = $(this),
					id = _this.attr('statusid');
				if($(this).hasClass("active")) {
					status = 0;
				}

				$("#passwordModal [name=id]").val(id);
				$("#passwordModal [name=status]").val(status);
				$("#passwordModal").modal("show");
			})

			function changeSave() {
				$.ajax({
					type: 'post',
					url: url + 'Back_ProjectUpdate',
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify({
							id: $("#passwordModal [name=id]").val(),
							need_pledge: Number($("#passwordModal [name=status]").val()),
							op_password: $("#passwordModal [name=op_password]").val(),
							status: 1
						})
					},
					dataType: 'json',
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.msg);
							return false;
						}

						var _this = $(".Status[statusId=" + $("#passwordModal [name=id]").val() + "]");
						$("#passwordModal").modal('hide');
						if($("#passwordModal [name=status]").val() == 0) {
							_this.removeClass("active");
							_this.find(".fr_swich_txt").text("不需要");
						} else {
							_this.addClass("active");
							_this.find(".fr_swich_txt").text("需要");
						}

					}
				})
			}
			//				
			//			})

			function editProject(_this) {
				var data = JSON.parse($(_this).siblings("input").val());
//				if(data.need_pledge == 0) {
//					$("#editprojectModal [name=pledge_num]").prop("disabled", true);
//				} else {
//					$("#editprojectModal [name=pledge_num]").prop("disabled", false);
//				}
				$.each(data, function(index, item) {
					if(index == 'password') {
						return;
					}
					$("#editprojectModal [name=" + index + "]").val(item);
				})
				$("#editprojectModal [name = orig_address]").val(data.address)
				$("#editprojectModal [name = pledge_num]").val(0)
				$("#editprojectModal").modal("show");
			}

			function editSave() {
				if($("#editprojectModal [name=op_password]").val() == "") {
					alert("请填写操作密码");
					return false;
				}
				var data = {
					account: $("#editprojectModal [name=account]").val(),
					phone: $("#editprojectModal [name=phone]").val(),
					pledge_num: $("#editprojectModal [name=pledge_num]").val(),
					op_password: $("#editprojectModal [name=op_password]").val(),
					id: $("#editprojectModal [name=id]").val(),
				}
				if($("#editprojectModal [name=orig_address]").val() != $("#editprojectModal [name=address]").val()) {
					data.address = $("#editprojectModal [name=address]").val()
				}
				if($("#editprojectModal [name=password]").val() != "") {
					data.password = $("#editprojectModal [name=password]").val()
				}
				$("[name = op_password]").val("");
				$.ajax({
					type: 'post',
					url: url + 'Back_ProjectUpdate',
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify(data)
					},
					dataType: 'json',
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.msg);
							return false;
						}
						$("#editprojectModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function Transfer(_this) {
				var data = JSON.parse($(_this).siblings("input").val());
				$("#transferModal").modal('show');
				$("#transferModal [name = op_password]").val("");
				$("#transferModal [name = coin_id]").attr("coin_id", data.coin_id)
			}

			function transferSave() {
				var data = {
					op_password: $("#transferModal [name=op_password]").val(),
					coin_num: $("#transferModal [name=coin_num]").val(),
					coin_id: $("#transferModal [name=coin_id]").attr("coin_id"),
				}
				$.ajax({
					type: 'post',
					url: url + 'Back_TransferCoinByPro',
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify(data)
					},
					dataType: 'json',
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.msg);
							return false;
						}
						$("#transferModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}
			
			function recharge(_this){
				console.log($(_this).siblings("input").val())
				var data = JSON.parse($(_this).siblings("input").val());
				$("#rechargeModal").modal('show');
				$("#rechargeModal [name = op_password]").val("");
				$("#rechargeModal [name = id]").val(data.id);
			}
			
			function rechargeSave(){
				if($("#rechargeModal [name=op_password]").val() == "") {
					alert("请填写操作密码");
					return false;
				}
				var data = {
					pledge_num: $("#rechargeModal [name=pledge_num]").val(),
					op_password: $("#rechargeModal [name=op_password]").val(),
					id: $("#rechargeModal [name=id]").val(),
				}
				$("[name = op_password]").val("");
				$.ajax({
					type: 'post',
					url: url + 'Back_ProjectUpdate',
					contentType: "application/x-www-form-urlencoded",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					data: {
						data: JSON.stringify(data)
					},
					dataType: 'json',
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.msg);
							return false;
						}
						$("#rechargeModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}
		</script>
	</body>

</html>